]> git.r.bdr.sh - rbdr/junction/blob - safari/Junction Extension/SafariWebExtensionHandler.swift
Add credits
[rbdr/junction] / safari / Junction Extension / SafariWebExtensionHandler.swift
1 import SafariServices
2 import os.log
3
4 class SafariWebExtensionHandler: NSObject, NSExtensionRequestHandling {
5
6 func beginRequest(with context: NSExtensionContext) {
7 let request = context.inputItems.first as? NSExtensionItem
8
9 let profile: UUID?
10 if #available(iOS 17.0, macOS 14.0, *) {
11 profile = request?.userInfo?[SFExtensionProfileKey] as? UUID
12 } else {
13 profile = request?.userInfo?["profile"] as? UUID
14 }
15
16 let message: Any?
17 if #available(iOS 17.0, macOS 14.0, *) {
18 message = request?.userInfo?[SFExtensionMessageKey]
19 } else {
20 message = request?.userInfo?["message"]
21 }
22
23 os_log(.default, "Received message from browser.runtime.sendNativeMessage: %@ (profile: %@)", String(describing: message), profile?.uuidString ?? "none")
24
25 let response = NSExtensionItem()
26 response.userInfo = [ SFExtensionMessageKey: [ "echo": message ] ]
27
28 context.completeRequest(returningItems: [ response ], completionHandler: nil)
29 }
30
31 }